#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include <bitset>
using namespace std;
using ull = unsigned long long;
using i128 = __int128_t;
//inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
#define int long long

const int N = 1e5 + 10;

vector<int>arr(N);

int e[N * 2],ne[N * 2],h[N],idx;
int fa[N][25];
int depth[N];
bitset<25> ba[N][25];
void add(int a,int b)
{
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx++;
}

void dfs(int node,int fat)
{
    fa[node][0] = fat;
    ba[node][0].set(arr[node],1);
    depth[node] = depth[fat] + 1;
    for(int i = 0; i <= 22; i ++)
    {
        fa[node][i] = fa[fa[node][i - 1]][i - 1];
        ba[node][i] = ba[fa[node][i - 1]][i - 1] | ba[node][i - 1];
    }
    for(int i = h[node]; i != -1; i = ne[i])
    {
        int j = e[i];
        if(j == fat) continue;
        dfs(j,node);
    }

}

int lca(int a,int b)
{
    bitset<25> ans;
    if(depth[a] < depth[b]) swap(a,b);
    for(int i = 22; i >= 0; i --)
    {
        if(depth[fa[a][i]] >= depth[b])
        {
            ans = ba[a][i] | ans; 
            a = fa[a][i];
        }
    }
    if(a == b)
    {
        ans = ans | ba[a][0];
        return ans.count();
    }
    for(int i = 22; i >= 0; i --)
    {
        if(fa[a][i] != fa[b][i])
        {
            ans = ans | ba[a][i];
            ans = ans | ba[b][i];
            a = fa[a][i];
            b = fa[b][i];
        }
    }
    ans = ans | ba[a][0];
    ans = ans | ba[b][0];
    ans[arr[fa[a][0]]] = 1;
    return ans.count();
}

int main()
{
    int n,m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++) cin >> arr[i];
    for(int i = 1; i <= n - 1; i ++)
    {
        int a,b;
        cin >> a >> b;
        add(a,b);
        add(b,a);
    }
    dfs(1,0);
    while(m--)
    {
        int a,b;
        cin >> a >> b;
        cout << lca(a,b) << endl;
    }
}